<?php
class AccountrecordssController extends Controller
{
    public function actionIndex()
    {
        $this->render('index');
    }

    public function actionGetdata(){

        $page = $_REQUEST['page'];
        $rows = $_REQUEST['rows'];
        $start = ($page-1)*$rows;
        $total = $this->connection->createCommand("select count(1) from crm_accountrecordss")->queryScalar();
        $result = $this->connection->createCommand("select * from crm_accountrecordss limit {$rows} offset {$start}")->queryAll();

        $data = Array();
        $data['total'] = $total;
        $data['rows'] = $result;

        echo json_encode($data);
    }

    public function actionShowedit(){

        $accountrecordss_id = $_REQUEST['accountrecordss_id'];

        $accountrecordss = null;
        if($accountrecordss_id==0){
            //新增
        }else{
            //编辑
            $accountrecordss = $this->connection->createCommand("select * from crm_accountrecordss where accountrecordss_id = :accountrecordss_id")->bindParam(':accountrecordss_id',$accountrecordss_id,PDO::PARAM_INT)->queryRow();
        }

        $this->render('showedit',['accountrecordss'=>$accountrecordss]);
    }

    public function actionSavedata(){

        $accountrecordss_id = $_REQUEST['accountrecordss_id'];
        $title = $_REQUEST['title'];
        $customer = $_REQUEST['customer'];
        $start_date = $_REQUEST['start_date'];
        $serviceitem = $_REQUEST['serviceitem'];
        $feedback = $_REQUEST['feedback'];
        $contacter = $_REQUEST['contacter'];

        if($accountrecordss_id!=null){
            //编辑
            $this->connection->createCommand("update crm_accountrecordss set title = :title,customer = :customer,start_date=:start_date,
serviceitem=:serviceitem, feedback=:feedback,contacter=:contacter
where accountrecordss_id = :accountrecordss_id")
                ->bindParam(':accountrecordss_id',$accountrecordss_id,PDO::PARAM_INT)
                ->bindParam(':title',$title,PDO::PARAM_STR)
                ->bindParam(':customer',$customer,PDO::PARAM_STR)
                ->bindParam(':start_date',$start_date,PDO::PARAM_STR)
                ->bindParam(':serviceitem',$serviceitem,PDO::PARAM_STR)
                ->bindParam(':feedback',$feedback,PDO::PARAM_STR)
                ->bindParam(':contacter',$contacter,PDO::PARAM_STR)
                ->execute();
        }else{
            //添加
            $this->connection->createCommand("insert into crm_accountrecordss (title,customer,start_date,serviceitem,feedback,contacter) values 
(:title,:customer,:start_date,:serviceitem,:feedback,:contacter) ")
                ->bindParam(':title',$title,PDO::PARAM_STR)
                ->bindParam(':customer',$customer,PDO::PARAM_STR)
                ->bindParam(':start_date',$start_date,PDO::PARAM_STR)
                ->bindParam(':serviceitem',$serviceitem,PDO::PARAM_STR)
                ->bindParam(':feedback',$feedback,PDO::PARAM_STR)
                ->bindParam(':contacter',$contacter,PDO::PARAM_STR)
                ->execute();
        }
    }

}